package com.ctyon.watchmanager.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.ctyon.watchmanager.R;
import com.ctyon.watchmanager.ui.BaseActivity;
import com.ctyon.watchmanager.ui.BaseFragment;
import com.ctyon.watchmanager.ui.fragment.AboutFragment;
import com.ctyon.watchmanager.ui.fragment.AddWatchFragment;
import com.ctyon.watchmanager.ui.fragment.AddWatchInputFragment;
import com.ctyon.watchmanager.ui.fragment.AlarmFragment;
import com.ctyon.watchmanager.ui.fragment.CallFragment;
import com.ctyon.watchmanager.ui.fragment.CameraFragment;
import com.ctyon.watchmanager.ui.fragment.ContactsAddFragment;
import com.ctyon.watchmanager.ui.fragment.ContactsFragment;
import com.ctyon.watchmanager.ui.fragment.ContactsImportFragment;
import com.ctyon.watchmanager.ui.fragment.DisableFragment;
import com.ctyon.watchmanager.ui.fragment.FindFragment;
import com.ctyon.watchmanager.ui.fragment.FlowerFragment;
import com.ctyon.watchmanager.ui.fragment.IntervalFragment;
import com.ctyon.watchmanager.ui.fragment.StrangeCallFragment;
import com.ctyon.watchmanager.ui.fragment.MapFragment;
import com.ctyon.watchmanager.ui.fragment.MapHistoryFragment;
import com.ctyon.watchmanager.ui.fragment.MessageFragment;
import com.ctyon.watchmanager.ui.fragment.MineInfoFragment;
import com.ctyon.watchmanager.ui.fragment.MoneyFragment;
import com.ctyon.watchmanager.ui.fragment.PowerFragment;
import com.ctyon.watchmanager.ui.fragment.ProgramFragment;
import com.ctyon.watchmanager.ui.fragment.RetrieveFragment;
import com.ctyon.watchmanager.ui.fragment.SmsFragment;
import com.ctyon.watchmanager.ui.fragment.SosFragment;
import com.ctyon.watchmanager.ui.fragment.StepFragment;
import com.ctyon.watchmanager.ui.fragment.VideoFragment;
import com.ctyon.watchmanager.ui.fragment.VoiceFragment;
import com.ctyon.watchmanager.ui.fragment.WatchFragment;
import com.orhanobut.logger.Logger;

import androidx.fragment.app.FragmentManager;

import static com.ctyon.common.container.ARouterPath.ROUTER_ACTIVITY_CONTAINER;

@Route(path = ROUTER_ACTIVITY_CONTAINER)
public class ContainerActivity extends BaseActivity {

    public final static String TAB_INDEX_PARAM = "fragmentType";
    public final static String PARAM1 = "param1";
    public final static String PARAM2 = "param2";
    public final static String PARAM3 = "param3";
    public final static String PARAM4 = "param4";

    private FragmentManager fragmentManager;
    private TextView txtTitle;

    @Autowired()
    public String fragmentType;

    @Autowired()
    public String param1;

    @Autowired()
    public String param2;

    @Autowired()
    public String param3;

    @Autowired()
    public String param4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_container);

        ARouter.getInstance().inject(this);

        fragmentManager = getSupportFragmentManager();
        txtTitle = findViewById(R.id.container_title);

        if (savedInstanceState == null && null != fragmentType && !"".equals(fragmentType)) {
            loadFragment(fragmentType);
        }

    }

    private void loadFragment(String fragmentType) {
        Logger.i("loadFragment : " + fragmentType);
        BaseFragment fragment = null;
        switch (fragmentType) {
            case RetrieveFragment.TAG://找回密码
                txtTitle.setText(getString(R.string.retrieve));
                fragment = RetrieveFragment.newInstance();
                break;
            case AddWatchFragment.TAG://添加手表
                txtTitle.setText(getString(R.string.add_watch));
                fragment = AddWatchFragment.newInstance();
                break;
            case AddWatchInputFragment.TAG://添加手表-输入设备号添加
                txtTitle.setText(getString(R.string.add_watch_input));
                fragment = AddWatchInputFragment.newInstance(param1);
                break;
            case AlarmFragment.TAG://闹钟
                txtTitle.setText(getString(R.string.fragment_alarm));
                fragment = AlarmFragment.newInstance();
                break;
            case CameraFragment.TAG://远程拍照
                txtTitle.setText(getString(R.string.fragment_camera));
                fragment = CameraFragment.newInstance();
                break;
//            case ChatFragment.TAG://微聊
//                txtTitle.setText(getString(R.string.fragment_chat));
//                fragment = ChatFragment.newInstance();
//                break;
            case ContactsFragment.TAG://通讯录
                txtTitle.setText(getString(R.string.fragment_contacts));
                fragment = ContactsFragment.newInstance();
                break;
            case ContactsImportFragment.TAG://通讯录导入
                txtTitle.setText(getString(R.string.fragment_contacts_import));
                fragment = ContactsImportFragment.newInstance();
                break;
            case ContactsAddFragment.TAG://通讯录添加
                txtTitle.setText(getString(R.string.fragment_contacts_add));
                fragment = ContactsAddFragment.newInstance(param1, param2);
                break;
            case DisableFragment.TAG://上课禁用
                txtTitle.setText(getString(R.string.fragment_disable));
                fragment = DisableFragment.newInstance();
                break;
            case FindFragment.TAG://查找设备
                txtTitle.setText(getString(R.string.fragment_find));
                fragment = FindFragment.newInstance();
                break;
            case FlowerFragment.TAG://爱心奖励
                txtTitle.setText(getString(R.string.fragment_flower));
                fragment = FlowerFragment.newInstance();
                break;
            case StrangeCallFragment.TAG://陌生电话开关
                txtTitle.setText(getString(R.string.fragment_strange));
                fragment = StrangeCallFragment.newInstance();
                break;
            case MapFragment.TAG://位置信息
                txtTitle.setText(getString(R.string.fragment_map));
                fragment = MapFragment.newInstance(param1, param2);
                break;
            case MapHistoryFragment.TAG://位置信息
                txtTitle.setText(getString(R.string.fragment_map));
                fragment = MapHistoryFragment.newInstance();
                break;
            case MessageFragment.TAG://设备消息
                txtTitle.setText(getString(R.string.fragment_message));
                fragment = MessageFragment.newInstance();
                break;
            case MoneyFragment.TAG://话费流量
                txtTitle.setText(getString(R.string.fragment_money));
                fragment = MoneyFragment.newInstance();
                break;
            case PowerFragment.TAG://远程关机
                txtTitle.setText(getString(R.string.fragment_power));
                fragment = PowerFragment.newInstance();
                break;
            case ProgramFragment.TAG://程序控制
                txtTitle.setText(getString(R.string.fragment_program));
                fragment = ProgramFragment.newInstance();
                break;
            case SmsFragment.TAG://短信提醒
                txtTitle.setText(getString(R.string.fragment_sms));
                fragment = SmsFragment.newInstance();
                break;
            case SosFragment.TAG://SOS
                txtTitle.setText(getString(R.string.fragment_sos));
                fragment = SosFragment.newInstance();
                break;
            case StepFragment.TAG://计步
                txtTitle.setText(getString(R.string.fragment_step));
                fragment = StepFragment.newInstance();
                break;
            case VideoFragment.TAG://视频聊天
                txtTitle.setText(getString(R.string.fragment_video));
                fragment = VideoFragment.newInstance();
                break;
            case VoiceFragment.TAG://语音监护
                txtTitle.setText(getString(R.string.fragment_voice));
                fragment = VoiceFragment.newInstance();
                break;
            case IntervalFragment.TAG://定位上报间隔
                txtTitle.setText(getString(R.string.fragment_interval));
                fragment = IntervalFragment.newInstance();
                break;
            case WatchFragment.TAG://手表详情
                txtTitle.setText(getString(R.string.fragment_watch));
                fragment = WatchFragment.newInstance();
                break;
            case CallFragment.TAG://拨打电话
                txtTitle.setText(getString(R.string.fragment_call));
                fragment = CallFragment.newInstance();
                break;
            case MineInfoFragment.TAG://拨打电话
                txtTitle.setText(getString(R.string.fragment_mine_info));
                fragment = MineInfoFragment.newInstance();
                break;
            case AboutFragment.TAG://关于
                txtTitle.setText(getString(R.string.fragment_about));
                fragment = AboutFragment.newInstance();
                break;
            default:
                finish();
                break;
        }
        if (null != fragment) {
            fragmentManager
                    .beginTransaction()
                    .add(R.id.fragment_container, fragment, fragmentType)
                    .commit();
        }

    }

    public void onBackClick(View view) {
        finish();
    }

}
